/**
 *
 */
import Util;
import OpenApi;
import OpenApiUtil;
import EndpointUtil;

extends OpenApi;


init(config: OpenApi.Config){
  super(config);
  @endpointRule = '';
  
  checkConfig(config);
  @endpoint = getEndpoint('dybaseapi', @regionId, @endpointRule, @network, @suffix, @endpointMap, @endpoint);
}

function getEndpoint(productId: string, regionId: string, endpointRule: string, network: string, suffix: string, endpointMap: map[string]string, endpoint: string) throws: string{
  if (!Util.empty(endpoint)) {
    return endpoint;
  }
  
  if (!Util.isUnset(endpointMap) && !Util.empty(endpointMap[regionId])) {
    return endpointMap[regionId];
  }
  return EndpointUtil.getEndpointRules(productId, regionId, endpointRule, network, suffix);
}

model QueryTokenForMnsQueueRequest {
  messageType?: string(name='MessageType', description='This parameter is required.'),
  ownerId?: long(name='OwnerId'),
  queueName?: string(name='QueueName'),
  resourceOwnerAccount?: string(name='ResourceOwnerAccount'),
  resourceOwnerId?: long(name='ResourceOwnerId'),
}

model QueryTokenForMnsQueueResponseBody = {
  code?: string(name='Code'),
  message?: string(name='Message'),
  messageTokenDTO?: {
    accessKeyId?: string(name='AccessKeyId'),
    accessKeySecret?: string(name='AccessKeySecret'),
    createTime?: string(name='CreateTime'),
    expireTime?: string(name='ExpireTime'),
    securityToken?: string(name='SecurityToken'),
  }(name='MessageTokenDTO'),
  requestId?: string(name='RequestId'),
}

model QueryTokenForMnsQueueResponse = {
  headers?: map[string]string(name='headers'),
  statusCode?: int32(name='statusCode'),
  body?: QueryTokenForMnsQueueResponseBody(name='body'),
}

/**
 * @param request QueryTokenForMnsQueueRequest
 * @param runtime runtime options for this request RuntimeOptions
 * @return QueryTokenForMnsQueueResponse
 */
async function queryTokenForMnsQueueWithOptions(request: QueryTokenForMnsQueueRequest, runtime: Util.RuntimeOptions): QueryTokenForMnsQueueResponse {
  Util.validateModel(request);
  var query = {};
  if (!Util.isUnset(request.messageType)) {
    query['MessageType'] = request.messageType;
  }
  if (!Util.isUnset(request.ownerId)) {
    query['OwnerId'] = request.ownerId;
  }
  if (!Util.isUnset(request.queueName)) {
    query['QueueName'] = request.queueName;
  }
  if (!Util.isUnset(request.resourceOwnerAccount)) {
    query['ResourceOwnerAccount'] = request.resourceOwnerAccount;
  }
  if (!Util.isUnset(request.resourceOwnerId)) {
    query['ResourceOwnerId'] = request.resourceOwnerId;
  }
  var req = new OpenApi.OpenApiRequest{ 
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApi.Params{
    action = 'QueryTokenForMnsQueue',
    version = '2017-05-25',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

/**
 * @param request QueryTokenForMnsQueueRequest
 * @return QueryTokenForMnsQueueResponse
 */
async function queryTokenForMnsQueue(request: QueryTokenForMnsQueueRequest): QueryTokenForMnsQueueResponse {
  var runtime = new Util.RuntimeOptions{};
  return queryTokenForMnsQueueWithOptions(request, runtime);
}

